var t = getApp();

Page({
    data: {
        view_show: !1,
        id: "",
        uid: "",
        LoginStatus: "",
        reply_id: "",
        reply_type: "",
        message_show: !1,
        reply_show: !1,
        datas: {},
        screen_shot_src: [],
        label: [],
        hotCase: [],
        second_category: [],
        comment: [],
        ad3: {},
        star_value: 4,
        reply_text: "",
        commit_text: "",
        emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png"
    },
    onLoad: function(t) {
        t.id && this.setData({
            id: t.id
        });
        try {
            var e = wx.getStorageSync("uid");
            this.setData({
                uid: e
            });
        } catch (t) {
            console.log(t);
        }
        this.getDatas();
    },
    previewImage: function(t) {
        var e = t.currentTarget.dataset.index;
        wx.previewImage({
            current: this.data.screen_shot_src[e],
            urls: this.data.screen_shot_src
        });
    },
    gotoOther: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/others/case_library/case_detail/caseLibraryDetail?id=" + e
        });
    },
    tapLink: function(t) {
        var e = t.currentTarget.dataset.url;
        wx.navigateTo({
            url: "".concat(e)
        });
    },
    changeReplyLength: function(t) {
        var e = t.currentTarget.dataset.ind, a = this.data.comment;
        a[e].is_show = !a[e].is_show, this.setData({
            comment: a
        });
    },
    openMeaage: function() {
        this.setData({
            reply_show: !1,
            reply_id: "",
            reply_text: "",
            message_show: !0
        });
    },
    messageText: function(t) {
        this.setData({
            commit_text: t.detail.value
        });
    },
    sendText: function(t) {
        this.setData({
            reply_text: t.detail.value
        });
    },
    delComment: function(t) {
        var e = t.currentTarget.dataset.str, a = t.currentTarget.dataset.id;
        this.del(e, a);
    },
    del: function(e, a) {
        var s = this;
        wx.showModal({
            title: "提示",
            content: "确定删除此留言?",
            success: function(o) {
                if (o.confirm) {
                    var n = t.getNetAddresss("plugin.case-library.api.release.del-comment");
                    t._postNetWork({
                        url: n,
                        data: {
                            id: a,
                            comment_type: e
                        },
                        success: function(t) {
                            var e = t.data;
                            1 == e.result ? (wx.showToast({
                                title: e.msg,
                                icon: "none",
                                duration: 1e3
                            }), s.getDatas()) : wx.showToast({
                                title: e.msg,
                                icon: "none",
                                duration: 1e3
                            });
                        },
                        fail: function(t) {
                            console.log(t);
                        }
                    });
                }
            }
        });
    },
    openReply: function(t) {
        var e = t.currentTarget.dataset.id, a = t.currentTarget.dataset.num;
        this.setData({
            message_show: !1,
            commit_text: "",
            reply_show: !0,
            reply_id: e,
            reply_type: a
        });
    },
    sendMessage: function(e) {
        var a = this, s = {}, o = "";
        1 == e.currentTarget.dataset.num ? (s = {
            reply_id: a.data.reply_id,
            reply_type: a.data.reply_type,
            contents: a.data.reply_text
        }, o = "plugin.case-library.api.release.reply-comment") : (s = {
            case_id: a.data.id,
            level: a.data.star_value,
            contents: a.data.commit_text
        }, o = "plugin.case-library.api.release.release-comment");
        var n = t.getNetAddresss(o);
        t._postNetWork({
            url: n,
            data: s,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (wx.showToast({
                    title: e.msg,
                    duration: 1e3,
                    icon: "none"
                }), a.setData({
                    star_value: 4,
                    commit_text: "",
                    reply_text: "",
                    message_show: !1,
                    reply_id: "",
                    reply_show: ""
                }), a.getDatas()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.datas.case_name,
            path: "/packageG/index/index?id=" + this.data.id,
            imageUrl: this.data.datas.img_src
        };
    },
    getDatas: function() {
        var e = this, a = t.getNetAddresss("plugin.case-library.api.case.get-case-detail");
        t._postNetWork({
            url: a,
            data: {
                id: e.data.id
            },
            success: function(t) {
                var a = t.data;
                if (1 == a.result) {
                    e.setData({
                        view_show: !0,
                        datas: a.data.case,
                        screen_shot_src: a.data.case.screen_shot_src || [],
                        label: a.data.case.label || [],
                        hotCase: a.data.hotCase,
                        second_category: a.data.case.second_category,
                        comment: a.data.case.comment
                    }), console.log(e.data.datas.id), e.data.comment.forEach(function(t, a) {
                        e.data.comment[a].is_show = !1;
                    });
                    var s = e.data.datas;
                    e.data.ad3 = a.data.advert.ad3.length && 0 == a.data.advert.ad3.length ? {} : a.data.advert.ad3, 
                    e.setData({
                        comment: e.data.comment,
                        five: String((Number(s.five_level) / Number(s.total_level) * 100).toFixed(2)),
                        four: String((Number(s.four_level) / Number(s.total_level) * 100).toFixed(2)),
                        three: String((Number(s.three_level) / Number(s.total_level) * 100).toFixed(2)),
                        two: String((Number(s.two_level) / Number(s.total_level) * 100).toFixed(2)),
                        one: String((Number(s.one_level) / Number(s.total_level) * 100).toFixed(2)),
                        ad3: e.data.ad3
                    });
                } else wx.showToast({
                    title: a.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});